﻿(function ($) {
    $.spiltpage = function () { };
    $.extend($.spiltpage,
              {
                  //创建分页html
                  CreateSpiltPageHtml: CreateSpiltPageHtmlHandle
              }
    );
    

})(jQuery);

/*创建分页html
*/
function CreateSpiltPageHtmlHandle(params) {
    var Html = "";
    var containerId = params.containerId;
    var pageIndex = params.pageIndex;
    var pageSize = params.pageSize;
    var totalCount = params.totalCount;
    var totalPages = params.totalPages;
    var hasPreviousPage = params.hasPreviousPage;
    var hasNextPage = params.hasNextPage;
    if (totalCount > 0) {
        Html = "<div class=\"splitPageBox\">" +
                        "<a id=\"homePage\" class=\"pageBtn\">首页</a>" +
                        "<a id=\"pagePrev\" class=\"pageBtn\">上一页</a>" +
                        "<a id=\"pageNext\" class=\"pageBtn\">下一页</a>" +
                        "<a id=\"lastPage\" class=\"pageBtn\">尾页</a>" +
                        "<div class=\"pageInfo\">" +
                            "共" + totalCount + "条数据，当前第" + (pageIndex + 1) + "/" + totalPages + "页" +
                        "</div>" +
                    "</div>";
        $("#" + containerId).html(Html);
        var homeBtn = $(".splitPageBox #homePage");
        var prevBtn = $(".splitPageBox #pagePrev");
        var nextBtn = $(".splitPageBox #pageNext");
        var lastBtn = $(".splitPageBox #lastPage");
        //首页
        homeBtn.bind("click", function () {
            goHome();//在需要调用的地方创建此方法
        });
        //上一页
        prevBtn.bind("click", function () {
            goPro();
        });
        //下一页
        nextBtn.bind("click", function () {
            goNext();
        });
        //尾页
        lastBtn.bind("click", function () {
            goLast();
        });

        if (pageIndex + 1 == totalPages) {
            nextBtn.removeClass("pageBtn");
            nextBtn.addClass("unWork");
            nextBtn.unbind("click");

            lastBtn.removeClass("pageBtn");
            lastBtn.addClass("unWork");
            lastBtn.unbind("click");
        }
        if (pageIndex == 0) {
            homeBtn.removeClass("pageBtn");
            homeBtn.addClass("unWork");
            homeBtn.unbind("click");

            prevBtn.removeClass("pageBtn");
            prevBtn.addClass("unWork");
            prevBtn.unbind("click");
        }        
    }
    else {
        $("#" + containerId).html("");
    }
}